package com.xindz.cn.mvptest.components.main.view;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.blankj.utilcode.util.ActivityUtils;
import com.xindz.cn.mvptest.R;
import com.xindz.cn.mvptest.base.BaseFragment;
import com.xindz.cn.mvptest.base.BasePresenter;
import com.xindz.cn.mvptest.base.BaseView;
import com.xindz.cn.mvptest.components.main.data.StartBean;
import com.xindz.cn.mvptest.components.main.data.TranBean;


import java.util.List;

public class MainFragmentFragment extends BaseFragment {


    private ListView listView;
    private FragListAdapter listAdapter;
    public List<StartBean> soragecList;

    public MainFragmentFragment() {
    }

    @SuppressWarnings("unused")
    public static MainFragmentFragment newInstance(TranBean tranBean) {
        MainFragmentFragment fragment = new MainFragmentFragment();
        Bundle args = new Bundle();
        args.putSerializable("DATA", tranBean);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setNotMVP();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        TranBean tranBean = (TranBean) getArguments().getSerializable("DATA");
        soragecList = tranBean.soragecList;

        View view = inflater.inflate(R.layout.frag_main_list, container, false);
        listView = view.findViewById(R.id.list);
        listAdapter = new FragListAdapter(soragecList, getActivity());
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ActivityUtils.startActivity(getActivity(), soragecList.get(position).clz);
            }
        });


        return view;
    }


    @Override
    public BasePresenter createPresneter() {
        return null;
    }

    @Override
    public BaseView createView() {
        return null;
    }
}
